package cn.edu.hunan.pm.controller;

import cn.edu.hunan.pm.Entity.Patent;
import cn.edu.hunan.pm.service.PatentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/patents")
@CrossOrigin(origins = "http://localhost:8080")
public class PatentController {
    @Autowired
    private PatentService patentService;

    @GetMapping
    public List<Patent> getAllPatents() {
        return patentService.getAllPatents();
    }

    @PostMapping
    public void addPatent(@RequestBody Patent patent) {
        patentService.addPatent(patent);
    }

    @PutMapping
    public void updatePatent(@RequestBody Patent patent) {
        patentService.updatePatent(patent);
    }

    @DeleteMapping("/{patentID}")
    public void deletePatent(@PathVariable int patentID) {
        patentService.deletePatent(patentID);
    }
}
